package com.minimalist.basic.controller.lindi;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplicationinvoice.LindiTradeApplicationInvoiceQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationinvoice.LindiTradeApplicationInvoiceVO;
import com.minimalist.common.feign.client.lindi.LindiTradeApplicationInvoiceFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 林地指标交易平台_交易申请发票控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_交易申请发票管理")
@RequestMapping("/basic/lindi/tradeApplicationInvoice")
public class LindiTradeApplicationInvoiceController{

    @Autowired
    private LindiTradeApplicationInvoiceFeignClient feignClient;

    @PostMapping("/addTradeApplicationInvoice")
    @Operation(summary = "添加交易申请发票")
    @SaCheckPermission("lindi:tradeApplicationInvoice:add")
    public R<?> addTradeApplicationInvoice(
            @RequestBody @Validated(Add.class) LindiTradeApplicationInvoiceVO
                    tradeApplicationInvoiceVO){
        tradeApplicationInvoiceVO.setCreateId(StpUtil.getLoginIdAsLong());
        tradeApplicationInvoiceVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        tradeApplicationInvoiceVO.setCreateTime(now);
        tradeApplicationInvoiceVO.setUpdateTime(now);
        return feignClient.addTradeApplicationInvoice(tradeApplicationInvoiceVO);
    }

    @DeleteMapping("/deleteTradeApplicationInvoiceByTradeApplicationInvoiceId")
    @Operation(summary = "删除交易申请发票 -> 根据交易申请发票ID删除")
    @SaCheckPermission("lindi:tradeApplicationInvoice:delete")
    public R<?> deleteTradeApplicationInvoiceByTradeApplicationInvoiceId(
            @RequestParam("tradeApplicationInvoiceId")
            @NotNull(message = "交易申请发票ID不能为空")
            @Parameter(name = "tradeApplicationInvoiceId", required = true, description = "交易申请发票ID")
            Long tradeApplicationInvoiceId){
        return feignClient.deleteTradeApplicationInvoiceByTradeApplicationInvoiceId(
                tradeApplicationInvoiceId);
    }

    @PutMapping("/updateTradeApplicationInvoiceByTradeApplicationInvoiceId")
    @Operation(summary = "修改交易申请发票")
    @SaCheckPermission("lindi:tradeApplicationInvoice:update")
    public R<?> updateTradeApplicationInvoiceByTradeApplicationInvoiceId(
            @RequestBody @Validated(Update.class) LindiTradeApplicationInvoiceVO
                    tradeApplicationInvoiceVO){
        tradeApplicationInvoiceVO.setUpdateId(StpUtil.getLoginIdAsLong());
        tradeApplicationInvoiceVO.setUpdateTime(LocalDateTime.now());
        return feignClient.updateTradeApplicationInvoiceByTradeApplicationInvoiceId(tradeApplicationInvoiceVO);
    }

    @GetMapping("/getPageTradeApplicationInvoiceList")
    @Operation(summary = "查询交易申请发票列表(分页)")
    @SaCheckPermission("lindi:tradeApplicationInvoice:get")
    public R<PageResp<LindiTradeApplicationInvoiceVO>> getPageTradeApplicationInvoiceList(
            LindiTradeApplicationInvoiceQueryVO queryVO){
        return feignClient.getPageTradeApplicationInvoiceList(queryVO);
    }

    @GetMapping("/getTradeApplicationInvoiceByTradeApplicationInvoiceId/{tradeApplicationInvoiceId}")
    @Operation(summary = "根据交易申请发票ID查询交易申请发票")
    @SaCheckPermission("lindi:tradeApplicationInvoice:get")
    public R<LindiTradeApplicationInvoiceVO> getTradeApplicationInvoiceByTradeApplicationInvoiceId(
            @PathVariable(value = "tradeApplicationInvoiceId")
            @NotNull(message = "交易申请发票ID不能为空")
            @Parameter(name = "tradeApplicationInvoiceId", description = "交易申请发票ID", required = true)
            Long tradeApplicationInvoiceId){
        return feignClient.getTradeApplicationInvoiceByTradeApplicationInvoiceId(tradeApplicationInvoiceId);
    }

    @GetMapping("/getTradeApplicationInvoiceListByTradeApplicationId")
    @Operation(summary = "根据交易申请ID查询发票列表")
    @SaCheckPermission("lindi:tradeApplicationInvoice:get")
    public R<List<LindiTradeApplicationInvoiceVO>> getTradeApplicationInvoiceListByTradeApplicationId(
            @RequestParam("tradeApplicationId")
            @NotNull(message = "交易申请ID不能为空")
            @Parameter(name = "tradeApplicationId", required = true, description = "交易申请ID")
            Long tradeApplicationId){
        return feignClient.getTradeApplicationInvoiceListByTradeApplicationId(tradeApplicationId);
    }
}